<?php
class Default_NewsController extends ZF_DefaultController{
	protected $save_data_counter = 3;
	public function detailAction(){
              if ($this->getRequest()->isGet()) {
                  $id_news = $this->getParam('id');
                  $dbcache=$this->getInvokeArg('bootstrap')->getResource('cachemanager')->getCache('dbcache');
                  $id = "news_".$id_news;
                  if(!$dbcache->load($id)){
                    $model = new Default_Model_News();                    
                    $data = $model->getById($id_news);
                    $dbcache->save($data,$id);  
                  }
                  $data = $dbcache->load($id);                  
                  if($data['view_counter'] % $this->save_data_counter == 0){
                    $model = new Default_Model_News();                    
                    $model->getById($id_news);                    
                    $model->setView_Counter($data['view_counter'] );
                    $model->update();
                  }
                  $data['view_counter'] = $data['view_counter'] + 1;
                  $dbcache->save($data,$id);
                 
                  $this->view->news = $data;
              }
        }
        
        public function listnewsAction(){
            $model_news =  new Default_Model_NewsCategory();
            $model_detail_news = new Default_Model_News();
            $data_hot_news = $model_detail_news->listAll(3,"view_counter");
            $data_domestic_news = $model_news->getByIdCategory(2,3,0,"timestamp");
            $data_international_news = $model_news->getByIdCategory(3,3,0,"timestamp");
            $data_public_health = $model_news->getByIdCategory(4,3,0,"timestamp");
            
            $this->view->title_hot_news = "Hot News";
            $this->view->title_domestic_news = "Tin trong nước ";
            $this->view->title_international_news = "Tin quốc tế";
            $this->view->title_public_health = "Sức khỏe cộng đồng";
            
            $this->view->hot_news = $data_hot_news;
            $this->view->domestic_news = $data_domestic_news;
            $this->view->international_news = $data_international_news;
            $this->view->public_health = $data_public_health;
            
        }
        public function charityAction(){
            $model_charity = new Default_Model_NewsCategory();
            $data = $model_charity->getByIdCategory(5,10,0,"timestamp");
            $this->view->charities = $data;
        }
        
        
}